package org.example.iol;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TextCopyFile {
    public static void main(String[] args) throws IOException {
        copyFile("E:/zzz.txt","E:/zzzCopy.txt");
    }

    //定义方法,实现文件复制
    public static void copyFile(String target, String newPath) throws IOException {
        FileInputStream fis = new FileInputStream(target); //读入目标文件
        FileOutputStream fos = new FileOutputStream(newPath); //写出新文件
        byte[] bytes = new byte[1024];
        int i = 0;
        while (fis.read(bytes) != -1) {
            //讲读取的数据写出到文件中
            fos.write(bytes);
        }
        fos.flush();
        fos.close();
    }
}
